package com.fr.base.print;

import com.fr.base.FRContext;
import com.fr.report.ArrayPageSet;
import com.fr.report.ReportPage;
import java.awt.print.PrinterException;
import java.io.ObjectInputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

public class PrintApplet extends JApplet
{
  private ReportPage[] pages;
  private boolean finished = false;

  public void init()
  {
    URL localURL = null;
    URLConnection localURLConnection = null;
    ObjectInputStream localObjectInputStream = null;
    try
    {
      localURL = new URL(getParameter("url"));
      localURLConnection = localURL.openConnection();
      localObjectInputStream = new ObjectInputStream(localURL.openStream());
      this.pages = ((ReportPage[])localObjectInputStream.readObject());
      boolean bool = ((Boolean)localObjectInputStream.readObject()).booleanValue();
      localObjectInputStream.close();
      localURLConnection = null;
      localURL = null;
      this.finished = true;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      JOptionPane.showMessageDialog(null, " e=" + localException.getMessage());
    }
    print();
  }

  public boolean isFinished()
  {
    return this.finished;
  }

  public void print()
  {
    if (this.pages != null)
      try
      {
        PrintUtils.print(new ArrayPageSet(this.pages, false));
      }
      catch (PrinterException localPrinterException)
      {
        FRContext.getLogger().log(Level.WARNING, localPrinterException.getMessage(), localPrinterException);
        JOptionPane.showMessageDialog(null, localPrinterException.getMessage());
      }
  }
}